<template>
  <ContentWrap>
      <!-- 搜索工作栏 -->
      <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="90px"
      >
      <el-form-item label="供应商编号" prop="supplierId">
          <el-input
            v-model="queryParams.supplierId"
            placeholder="请输入供应商编号"
            clearable
            class="!w-240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="入库批次" prop="batchCode">
          <el-input
            v-model="queryParams.batchCode"
            placeholder="请输入入库批次"
            clearable
            class="!w-240px"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="入库日期" prop="dateReq">
          <el-date-picker
            v-model="queryParams.dateReq"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            class="!w-400px"
          />
        </el-form-item>

        <el-form-item>
          <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
          <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
          <el-button
                type="warning"
                plain
                @click="handleImport"
              >
                <Icon icon="ep:upload" /> 导入
              </el-button>
          <!-- <el-button
            type="success"
            plain
            @click="handleExport"
            :loading="exportLoading"
            v-hasPermi="['system:post:export']"
          >
            <Icon icon="ep:download" class="mr-5px" /> 导出
          </el-button> -->
        </el-form-item>
      </el-form>
    </ContentWrap>
  <!-- 列表 -->
  <ContentWrap>
      <el-table v-loading="loading" :data="list">
        <el-table-column type="index" label="序号" align="center" width="55" />
        <el-table-column label="供应商编号" align="center" prop="supplierId" />
        <el-table-column label="供应商" align="center" prop="supplierName" />
        <el-table-column label="入库批次" align="center" prop="batchCode" />
        <el-table-column label="入库日期" align="center" prop="receiptDate" />
        <!-- <el-table-column label="审核标志" align="center" prop="auditMark" />
        <el-table-column label="批次号" align="center" prop="code" />
        <el-table-column label="收料仓库" align="center" prop="warehouse" />
        <el-table-column label="织板编码" align="center" prop="materialCode" />
        <el-table-column label="物料名称" align="center" prop="materialName" />
        <el-table-column label="规格型号" align="center" prop="specification" />
        <el-table-column label="应收数量" align="center" prop="receivableNum" />
        <el-table-column label="实收数量" align="center" prop="actualNum" />
        <el-table-column label="单位" align="center" prop="unit" /> -->
        <el-table-column label="操作" align="center" width="160">
          <template #default="scope">
            <div class="flex items-center justify-center">
              <el-button
                type="primary"
                link
                @click="openDetail(scope.row.receiptCode)"
              >查看
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
    <!-- 导入对话框 -->
    <maStorageImportForm ref="importFormRef" @success="getList" />
    <!-- 查看详情 -->
    <materialStorDetail ref="formRef" @success="getList" />
  </template>
  
  <script lang="ts" setup>
  import download from '@/utils/download'
  import * as materialStorageApi from '@/api/hcxly/materialStorage/Index'
  import maStorageImportForm from './maStorageImportForm.vue'
  import materialStorDetail from './materialStorDetail.vue'
  
  defineOptions({ name: 'materialStorage' })
  
  const message = useMessage() // 消息弹窗
  const { t } = useI18n() // 国际化
  
  const loading = ref(true) // 列表的加载中
  const total = ref(0) // 列表的总页数
  const list = ref([]) // 列表的数据
  const queryParams = reactive({
    pageNo: 1,
    pageSize: 10,
    supplierId: '',
    batchCode: '',
    dateReq: []
  })
  const queryFormRef = ref() // 搜索的表单
  
  /** 查询列表 */
  const getList = async () => {
    loading.value = true
    try {
      const data = await materialStorageApi.getmaterialStorage(queryParams)
      console.log(data)
      list.value = data.list
      total.value = data.total
    } finally {
      loading.value = false
    }
  }
  
  /** 搜索按钮操作 */
  const handleQuery = () => {
    queryParams.pageNo = 1
    getList()
  }
  
  /** 重置按钮操作 */
  const resetQuery = () => {
    queryFormRef.value.resetFields()
    handleQuery()
  }
  
  /** 导入 */
  const importFormRef = ref()
  const handleImport = () => {
    importFormRef.value.open()
  }

  /** 查看详情操作 */
  const formRef = ref()
  const openDetail = (id: string) => {
    console.log(id)
    formRef.value.open(id)
  }

  // const router = useRouter() // 路由
  // /** 查看详情 */
  // const { push } = useRouter()
  // const openDetail = (id) => {
  //   router.push({
  //     name: 'materialStorDetail',
  //     query: {
  //       id:id
  //     }
  //   })
  // }
  
  /** 初始化 **/
  onMounted(() => {
    getList()
  })
  
  </script>
